package com.File文件;

import java.io.*;

public class 对象序列化 {
    public static void main(String[] args) throws IOException {
        //创建序列化流输出文本文件的内容
        ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream
                ("D:\\黑马视频\\copyfile\\student.txt",true));
        //创建对象
        Student s = new Student("heima001", "张三", "25", "" +
                "1994-08-25", "安徽省合肥市包河区裸缸街道延安路777号");
        //输入数据
        oos.writeObject(s);
        //oos.write("\r\n".getBytes());
        //释放流
        oos.close();
    }
}

class Tests {
    public static void main(String[] args) throws IOException, ClassNotFoundException {
        //创建输入流
        ObjectInputStream ois = new ObjectInputStream(new FileInputStream("D:\\黑马视频\\copyfile\\student.txt"));
        //对象接收数据
        Student stu = null;
        Object object = null;
        //stu = (Student) ois.readObject();
        try {
            while (true) {
                object = ois.readObject();
                if (object instanceof Student) {
                    stu = (Student) object;
                    stu.show();
                } else {
                    break;
                }}
        } catch (Exception e) {
            System.out.println("读取完毕!");
        }


        //释放流
        ois.close();
    }
}
